package designPattern.creationpattern.prototype.deepCopy02;

import lombok.*;

import java.io.*;

/**
 * @author wei.zhao
 * @description: 简历
 * @date 2021年12月09日 16:12
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Resume implements Serializable {

    private static final long serialVersionUID = 1L;
    private String name;//姓名
    private String job;//岗位
    private String salary;//薪资
    private Witness witness;//证人

    public Resume deepClone() {
        Resume resume = null;
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        ByteArrayInputStream bis = null;
        ObjectInputStream ois = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(this);
            bis = new ByteArrayInputStream(bos.toByteArray());
            ois = new ObjectInputStream(bis);
            resume = (Resume) ois.readObject();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                bos.close();
                oos.close();
                bis.close();
                ois.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
        return resume;
    }

}
